package com.cos.openapi.web.controller;

import com.cos.openapi.common.Const;
import com.cos.openapi.common.ResponseResult;
import com.cos.openapi.common.ResultTable;
import com.cos.openapi.entity.AdminUser;
import com.cos.openapi.entity.Menu;
import com.cos.openapi.services.MenuServices;
import com.cos.openapi.services.impl.MenuServicesImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @author: COS
 * @time: 2021/11/24 9:50
 * @description:
 */

@RestController
@RequestMapping("/menu")
public class MenuController {
    @Autowired
    private MenuServices menuServices;

    @RequestMapping("/getMenu")
    public ResponseResult getMenu(HttpSession session){
       AdminUser user = (AdminUser) session.getAttribute(Const.IS_LOGIN);
        if (user == null) {
            return ResponseResult.getFail("请先登录");
        }
        //访问数据库,获取用户有权访问的菜单
        List<Menu> menus= menuServices.getMenuByUid(user.getId());
        return ResponseResult.getSuccess(menus);
    }

    @RequestMapping("/list")
    public ResultTable getLst(Integer page,Integer limit){
        return menuServices.getList(page,limit);
    }

    @RequestMapping("/info")
    public Menu getLst(Integer id){
        return menuServices.getMenuById(id);
    }

}
